package main

import (
	"reflect"
	"fmt"
)
//反射
func main(){
	var a int = 200
	test(a)
}

func test(b interface{})  {
	t := reflect.TypeOf(b)
	v := reflect.ValueOf(b)
	fmt.Println(t)
	fmt.Println(v)

	k := v.Kind()
	fmt.Println(k)

	var f float64 = 43.3
	testFloat(f)


	//reflect.TypeOf()	获取变量类型
	//reflect.ValueOf()	获取变量值
	//reflect.Value{}.Kind()	获取变量类别
	//reflect.Value{}.Interface()	转为interface{}类型
	//变量---->interface{}----->reflect.Value
}


func testFloat(b interface{}){
	t := reflect.TypeOf(b)
	fmt.Println(t)
	v := reflect.ValueOf(b)
	fmt.Println(v)
	fmt.Println(v.Type())
	fmt.Println(v.Kind())
	fmt.Println(v.Float())

	fmt.Println(v.Interface())
	fmt.Printf("value is %5.2e\n",v.Interface())
	y := v.Interface().(float64)
	fmt.Println(y)
}